﻿using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Dapper;
using Hx.Domain.Model;

namespace Hx.Domain.Repositories.Dapper
{
    public class CategoryRepository : DapperRepository<Category>, ICategoryRepository
    {
        public CategoryRepository(IRepositoryContext context)
            : base(context)
        {
        }

        public Category GetCategoryByTitle(string title)
        {
            return DapperContext.Connection.Get<Category>(new { Title = title });
        }

        public List<Category> GetAllCategories()
        {
            var sp = new Stopwatch();
            sp.Start();
            var result= DapperContext.Connection.Query<Category>("SELECT Id, Title, ParentId, ArticleCount, CreateTime, ModifyTime FROM Hx_Category").ToList();
            sp.Stop();
            Debug.WriteLine("SQL Query:" + sp.ElapsedMilliseconds);
            return result;
        }
    }
}